package top.itmeans.yes.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.itmeans.yes.common.api.CommonResult;
import top.itmeans.yes.entity.SkuStock;
import top.itmeans.yes.service.SkuStockService;

import java.util.List;

/**
 * 商品SKU库存管理Controller PMS
 * @author Yiming.Cao
 */
@RestController
@Api(tags = "SkuStockController")
@RequestMapping("/sku")
public class SkuStockController {
    @Autowired
    private SkuStockService skuStockService;

    @ApiOperation("根据商品ID及sku编码模糊搜索sku库存")
    @GetMapping("/{pid}")
    public CommonResult<List<SkuStock>> getList(@PathVariable Long pid, @RequestParam(value = "keyword",required = false) String keyword) {
        List<SkuStock> skuStockList = skuStockService.getList(pid, keyword);
        return CommonResult.success(skuStockList);
    }
    @ApiOperation("批量更新sku库存信息")
    @PostMapping("/{pid}")
    public CommonResult update(@PathVariable Long pid, @RequestBody List<SkuStock> skuStockList){
        int count = skuStockService.update(pid,skuStockList);
        if(count>0){
            return CommonResult.success(count);
        }else{
            return CommonResult.failed();
        }
    }
}
